package GUI;

import javax.swing.JPanel;
import java.awt.SystemColor;
import javax.swing.JLabel;
import java.awt.Font;
import java.awt.Color;

import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JButton;

import Client.BusinessImplements;
import Controler.Delete_Copy_controler;
import Controler.Update_Book_Details_controler;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import javax.swing.border.LineBorder;
/**
  * @author Lucie
 * Class name Detete_Copy_first_Panel
 * extend  Abstract_Jpanel
 * purpose: this panel get item id from the user and move on to 
 * next panel "Detete_Copy_secon_Panel" to delete one of the copy of the item id that was
 * chosen in this panel 
 */
public class Detete_Copy_first_Panel extends Abstract_Jpanel {
	private JTextField textField;

	/**
	 * Create the panel.
	 */
	public Detete_Copy_first_Panel() {
		setLayout(null);
		
		JPanel panel = new JPanel();
		panel.setBorder(new LineBorder(SystemColor.activeCaption, 6));
		panel.setBackground(SystemColor.inactiveCaption);
		panel.setBounds(24, 65, 523, 253);
		add(panel);
		panel.setLayout(null);
		
		JLabel lblBookId = new JLabel("book id:");
		lblBookId.setFont(new Font("Tahoma", Font.PLAIN, 14));
		lblBookId.setBounds(45, 74, 59, 17);
		panel.add(lblBookId);
		
		textField = new JTextField();
		textField.setBounds(128, 74, 167, 20);
		panel.add(textField);
		textField.setColumns(10);
		
		JLabel lblChooseBookId_1 = new JLabel("Choose a book that you want to delete a copy");
		lblChooseBookId_1.setForeground(Color.RED);
		lblChooseBookId_1.setFont(new Font("Segoe Print", Font.PLAIN, 13));
		lblChooseBookId_1.setBounds(54, 115, 337, 17);
		panel.add(lblChooseBookId_1);
		
		JLabel lblChooseBookId = new JLabel("Choose Book to delete");
		lblChooseBookId.setForeground(new Color(25, 25, 112));
		lblChooseBookId.setFont(new Font("MV Boli", Font.BOLD, 30));
		lblChooseBookId.setBounds(46, 21, 501, 43);
		add(lblChooseBookId);
		/*
		  *  btnBack ;When you click this button you will return to 
		 *  Sign_in_panel screen 
		 */
		JButton btnBack = new JButton("back");
		btnBack.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				Sign_in_panel sip=new Sign_in_panel();
				on_screen_unload();
				BusinessImplements.GetInstance().getMainFrame().setContentPane(sip);
				sip.setSize(getMaximumSize());
				sip.on_screen_load();

			}
		});
		btnBack.setFont(new Font("Tahoma", Font.PLAIN, 14));
		btnBack.setBounds(53, 343, 112, 38);
		add(btnBack);
		/*
		 * btnGo; When you click this button you will move to Delete_Copy_secon_Panel
		 *  we also send all the copies of the item chosen to the next screen
		 */
		JButton btnGo = new JButton("go");
		btnGo.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				Delete_Copy_controler deletecopy_controler=new Delete_Copy_controler();
		 		
		 		ArrayList<String> item_deatails=deletecopy_controler.get_item(get_book_id());
		 		if(!(item_deatails==null))
		 		{
		 		ArrayList<String> item_copys=deletecopy_controler.get_all_copys(get_book_id());
		 		if (!(item_copys==null))
		 		{
		 			Delete_Copy_secon_Panel next_screen=new Delete_Copy_secon_Panel();
		   		on_screen_unload();
		   		BusinessImplements.GetInstance().getMainFrame().setContentPane(next_screen);
		   		next_screen.setSize(getMaximumSize());
		   
		   		next_screen.on_screen_load(item_copys,item_deatails.get(1),item_deatails.get(0));
		 		}
		 		else
		 		{
		 			next_screen_faild( deletecopy_controler.get_msg());
		 		}
		 		}
		 		else
		 			
		 		{
		 			next_screen_faild( deletecopy_controler.get_msg());
		 		}
		 		
		}
		}
			);
		btnGo.setFont(new Font("Tahoma", Font.PLAIN, 14));
		btnGo.setBounds(446, 343, 112, 38);
		add(btnGo);

	}

	@Override
	public void next_screen() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void prev_screen() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void on_screen_load() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void on_screen_unload() {
		// TODO Auto-generated method stub
		
	}
	/**
	 * 
	 * @return book id
	 */
	public String get_book_id()
	{
		return textField.getText();
	}
	/**
	 * this method display showMessageDialog with a failed msg
	 * @param msg
	 */
	public void next_screen_faild(String msg)
	{
		JOptionPane.showMessageDialog(this,"apply faild "+msg);
	}
	
}
